/***************************************************************************
 *                                - io80C51BH.h -
 *
 * Special header for the Intel 80C51BH Microcontroller.
 *
 ***************************************************************************/

#ifndef __SFR_H
#define __SFR_H
#ifdef __IAR_SYSTEMS_ICC__
#ifndef _SYSTEM_BUILD
   #pragma system_include
#endif
#pragma language=save
#pragma language=extended

/*-------------------------------------------------------------------------
 *   8051 Core
 *-------------------------------------------------------------------------*/

__sfr __no_init volatile union
{
  unsigned char ACC; /* Accumulator */
  struct /* Accumulator */
  {
    unsigned char ACC0 : 1;
    unsigned char ACC1 : 1;
    unsigned char ACC2 : 1;
    unsigned char ACC3 : 1;
    unsigned char ACC4 : 1;
    unsigned char ACC5 : 1;
    unsigned char ACC6 : 1;
    unsigned char ACC7 : 1;
  } ACC_bit;
} @ 0xE0;
__sfr __no_init volatile union
{
  unsigned char PSW; /* Program Status Word */
  struct /* Program Status Word */
  {
    unsigned char P : 1;
    unsigned char F1 : 1;
    unsigned char OV : 1;
    unsigned char RS0 : 1;
    unsigned char RS1 : 1;
    unsigned char F0 : 1;
    unsigned char AC : 1;
    unsigned char CY : 1;
  } PSW_bit;
} @ 0xD0;
__sfr __no_init volatile unsigned char SP @ 0x81; /* Stack Pointer */
__sfr __no_init volatile unsigned char DPL @ 0x82; /* Data Pointer Low byte, LSB of DPTR */
__sfr __no_init volatile unsigned char DPH @ 0x83; /* Data Pointer High byte, MSB of DPTR */
__sfr __no_init volatile union
{
  unsigned char B; /* B Register */
  struct /* B Register */
  {
    unsigned char B0 : 1;
    unsigned char B1 : 1;
    unsigned char B2 : 1;
    unsigned char B3 : 1;
    unsigned char B4 : 1;
    unsigned char B5 : 1;
    unsigned char B6 : 1;
    unsigned char B7 : 1;
  } B_bit;
} @ 0xF0;

/*-------------------------------------------------------------------------
 *   Timers
 *-------------------------------------------------------------------------*/

__sfr __no_init volatile unsigned char TH0 @ 0x8C; /* Timer0 High */
__sfr __no_init volatile union
{
  unsigned char TCON; /* Timer Control */
  struct /* Timer Control */
  {
    unsigned char bit0 : 1;
    unsigned char bit1 : 1;
    unsigned char bit2 : 1;
    unsigned char bit3 : 1;
    unsigned char bit4 : 1;
    unsigned char bit5 : 1;
    unsigned char bit6 : 1;
    unsigned char bit7 : 1;
  } TCON_bit;
} @ 0x88;

#define TR0		TCON_bit.bit4
#define TF0		TCON_bit.bit5
#define TR1		TCON_bit.bit6
#define TF1		TCON_bit.bit7


__sfr __no_init volatile unsigned char TH1 @ 0x8D; /* Timer1 High */
__sfr __no_init volatile union
{
  unsigned char TMOD; /* Timer Mode */
  struct /* Timer Mode */
  {
    unsigned char M00 : 1;
    unsigned char M10 : 1;
    unsigned char C_T0 : 1;
    unsigned char GATE0 : 1;
    unsigned char M01 : 1;
    unsigned char M11 : 1;
    unsigned char C_T1 : 1;
    unsigned char GATE1 : 1;
  } TMOD_bit;
} @ 0x89;
__sfr __no_init volatile unsigned char TL0 @ 0x8A; /* Timer0 Low */
__sfr __no_init volatile unsigned char TL1 @ 0x8B; /* Timer1 Low */

/*-------------------------------------------------------------------------
 *   Interrupt
 *-------------------------------------------------------------------------*/

__sfr __no_init volatile union
{
  unsigned char IP; /* Interrupt Priority */
  struct /* Interrupt Priority */
  {
    unsigned char  : 1;         //reserved, it's not used
    unsigned char PT0 : 1;
    unsigned char  : 1;         //reserved, it's not used
    unsigned char PT1 : 1;
    unsigned char  : 1;         //reserved, it's not used
    unsigned char  : 1;         //reserved, it's not used
    unsigned char  : 2;         //reserved, it's not used
  } IP_bit;
} @ 0xB8;

__sfr __no_init volatile union
{
  unsigned char IE; /* Interrupt Enable */
  struct /* Interrupt Enable */
  {
    unsigned char bit0 : 1;
    unsigned char bit1 : 1;
    unsigned char bit2 : 1;
    unsigned char bit3 : 1;
    unsigned char bit4 : 1;
    unsigned char bit5 : 1;
    unsigned char bit6 : 1;
    unsigned char bit7 : 1;
  } IE_bit;
} @ 0xA8;

#define EA		IE_bit.bit7
#define ES1		IE_bit.bit6
#define ET2		IE_bit.bit5
#define ES0		IE_bit.bit4
#define ET1		IE_bit.bit3
#define EX1		IE_bit.bit2
#define ET0		IE_bit.bit1
#define EX0		IE_bit.bit0




/*
 * Interrupt Vectors
 */
#define TF0_int 0x0B /* Timer 0 Interrupt */
#define timer0 0x0B /* Timer 0 Interrupt */
#define TF1_int 0x1B /* Timer 1 Interrupt */
#define timer1 0x1B /* Timer 1 Interrupt */

#pragma language=restore
#endif  /* __IAR_SYSTEMS_ICC__  */

/***************************************************************************
 *   Assembler definitions
 *
 *   The following SFRs are built in in the a8051.exe and can not be
 *   defined explicitly in this file:
 *     ACC,B,PSW,SP,DPL,DPH
 *   The PSW-bits are built-in in the a8051.exe
 *     OV,AC,F0,RS0,RS1,P
 *
 ***************************************************************************/

#ifdef __IAR_SYSTEMS_ASM__
/*-------------------------------------------------------------------------
 *   Timers
 *-------------------------------------------------------------------------*/

TCON DEFINE 0x88 /* Timer Control */
TCON_TR0 DEFINE 0x88.4
TCON_TF0 DEFINE 0x88.5
TCON_TR1 DEFINE 0x88.6
TCON_TF1 DEFINE 0x88.7
TMOD DEFINE 0x89 /* Timer Mode */
TL0 DEFINE 0x8A /* Timer0 Low */
TL1 DEFINE 0x8B /* Timer1 Low */
TH0 DEFINE 0x8C /* Timer0 High */
TH1 DEFINE 0x8D /* Timer1 High */

/*-------------------------------------------------------------------------
 *   Interrupt
 *-------------------------------------------------------------------------*/

IE DEFINE 0xA8 /* Interrupt Enable */
IE_ET0 DEFINE 0xA8.1
IE_ET1 DEFINE 0xA8.3
IE_EA DEFINE 0xA8.7
IP DEFINE 0xB8 /* Interrupt Priority */
IP_PT0 DEFINE 0xB8.1
IP_PT1 DEFINE 0xB8.3
#endif /* __IAR_SYSTEMS_ASM__*/
#endif /* IO80C51BH_H */
